﻿using System.Linq;
using ESRI.ArcGIS.Client;
using QDP.Platform.ObjService;
using QDP.Platform.Services;
using QDP.Platform.Silverlight;
using QDP.Platform.Silverlight.Tools;
using Services.Maps;
namespace Apps.Maps
{
    public class MapOverlayerWidget : PartElement
    {
        private Layer overview;
        public Layer OverView
        {
            get
            {

                var mapServices = NavigationDirectoryHelper.RemoveDirectory(Q.Config.GisServiceConfig.MapServices);

                if (mapServices.Any(p => p is ServiceLayer && (p as ServiceLayer).ParmsExpression.IndexOf("overlayer;") >= 0))
                {
                    var layobj = mapServices.First(p => p is ServiceLayer
                             && (p as ServiceLayer).ParmsExpression.IndexOf("overlayer;") >= 0) as ServiceLayer;
                    overview = LayerFactory.CreateLayer(layobj);
                    overview.InitializationFailed += (s, e) => { };
                    overview.Initialize();
                }

                return this.overview;
            }
        }

        public IMapService Service
        {
            get
            { 
                return ServiceLoader.Load<IMapService>();
            }
        }
    }
}
